package com.cskaoyan.mall.product.controller;

import com.cskaoyan.mall.product.dto.CategoryHierarchyDTO;
import com.cskaoyan.mall.product.dto.PlatformAttrInfoDTO;
import com.cskaoyan.mall.product.dto.SkuInfoDTO;
import com.cskaoyan.mall.product.dto.TrademarkDTO;
import com.cskaoyan.mall.product.service.CategoryService;
import com.cskaoyan.mall.product.service.SkuService;
import com.cskaoyan.mall.product.service.TrademarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

/**
 * 搜索服务调用
 * @author Macro_Ray
 * @since 2024/6/21 上午12:31
 */
@RestController
@RequestMapping("")
public class ProductApiController {

    @Autowired
    SkuService skuService;
    @Autowired
    TrademarkService trademarkService;
    @Autowired
    CategoryService categoryService;

    /**
     * 根据skuId获取sku信息
     *
     * @param skuId
     */
    @GetMapping("/api/product/inner/getSkuInfo/{skuId}")
    SkuInfoDTO getSkuInfo(@PathVariable("skuId") Long skuId){
        return skuService.getSkuInfo(skuId);
    }

    /**
     * 根据skuId获取sku价格
     */
    @GetMapping("/api/product/inner/price/{skuId}")
    BigDecimal getPrice(@PathVariable("skuId") Long skuId){
        return skuService.getSkuPrice(skuId);
    }

    /**
     * 通过品牌Id 集合来查询数据
     *
     * @param tmId
     */
    @GetMapping("/api/product/inner/getTrademark/{tmId}")
    TrademarkDTO getTrademark(@PathVariable("tmId") Long tmId){
        return trademarkService.getTrademarkById(tmId);
    }

    /**
     * 通过三级分类id查询分类信息
     */
    @GetMapping("/api/product/inner/getCategoryView/{thirdLevelCategoryId}")
    CategoryHierarchyDTO getCategoryView(@PathVariable("thirdLevelCategoryId") Long thirdLevelCategoryId){
        return categoryService.getCateHierarchy(thirdLevelCategoryId);
    }

    /**
     * 通过skuId 集合来查询数据
     *
     * @param skuId
     */
    @GetMapping("/api/product/inner/getAttrList/{skuId}")
    List<PlatformAttrInfoDTO> getAttrList(@PathVariable("skuId") Long skuId){
        return skuService.getPlatformAttrInfoBySku(skuId);
    }

}
